<template>
    <ArticleList :articleList="result" :moduleTitle="title" :type="type" @onChange="onArticle"></ArticleList>
</template>

<script>
    import ArticleList from "@/components/ArticleList"
    import { categoryArticleList, tagArticleList } from '@/api/articleList'

    export default {
        name: "index",
        components: { ArticleList },
        data () {
            return {
                title: '',
                type: '',
                result: [],
            }
        },
        created () {
            let { id, title, type } = this.$route.query

            this.title = title
            this.type = type
            this[type](id)
        },
        methods: {
            // 分类
            async 'category' (id) {
                let { result } = await categoryArticleList(id)

                this.result = result
            },
            // 标签
            async 'tag' (id) {
                let { result } = await tagArticleList(id)
                console.log(result)

                this.result = result
            },
            onArticle (article) {
                this.$router.push({
                    name: 'article',
                    params: {
                        articleId: article.id
                    }
                })
            },
        },
    }
</script>

<style scoped>

</style>
